package com.example.springbootproject.service;


import com.example.springbootproject.dao.MyDao;
import com.google.common.util.concurrent.RateLimiter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

@Service
@Resource // java的注解
public class MyService {

    @Autowired
    private MyDao myDao;



    @Transactional(rollbackFor = Exception.class)
    public String test(String str){
        StringBuffer res = new StringBuffer();
        res.append("hello:").append(str);
        System.out.println("test hello :" + str);
        return res.toString();
    }

//    public Object sub(List<String> list){
//        return "";
//    }

    public Object sub(List<Integer> list){
        String[] words = {"w","wo","wor","woo","world"};
        Arrays.sort(words, (a,b)->{
            if (a.length() != b.length()){
                return a.length() - b.length();
            }else {
                return a.compareTo(b);
            }
        });

        RateLimiter rateLimiter = RateLimiter.create(3);
        return "";
    }

}
